﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Vigenère_cipher
{   /// <summary>
/// 建立一个维吉尼亚密码加密类
/// </summary>
    internal class MyEncode
    {   /// <summary>
    /// 定义明文
    /// </summary>
        public string PlainText { get; set; }
        /// <summary>
        /// 定义密文
        /// </summary>
        public string CipherText { get; set; }
        /// <summary>
        /// 定义密钥
        /// </summary>
        public string Key { get; set; }
        /// <summary>
        /// 加密过程
        /// </summary>
        public void EnCode()
        { for (int i = 0,j = 0;i<PlainText.Length;i++,j++)
            { if (j == Key.Length) j = 0;
                int Num = (Convert.ToInt32(PlainText[i]) + GetCodeNum(Key[j])-65)%26; //求转化后字母的数字编号
                CipherText += Convert.ToChar(Num + 'A');
            }
        }
        /// <summary>
        /// 求密钥字母的数字编号.
        /// </summary>
        public int GetCodeNum(char ch)
        { int CodeNum = ch - 'A';
        
            return CodeNum;
        }
         
    }
}
